<?php

namespace App\Service\App\V1;

use App\Mapper\V1\GoldBeanSignInMapper;
use App\Model\MallModel\TSelfGoods;
use App\Service\App\AppServiceResponse;
use App\ServiceApi\App\V1\Api\ICollectService;
use App\ServiceApi\App\V1\Api\IGoldBeanService;
use Hyperf\Di\Annotation\Inject;
use Psr\Http\Message\ResponseInterface;
use App\Annotation\Transaction;
use App\Annotation\Idempotent;
class GoldBeanServiceImpl extends AppServiceResponse implements IGoldBeanService
{

    /**
     * @Inject
     * @var GoldBeanSignInMapper
     */
    protected $goldBeanMapper;

    /**
     * 获取金豆任务列表
     */
    public function goldTaskList($user_id){
        $responseResult = $this->goldBeanMapper->goldTaskList($user_id);
        return $this->success($responseResult);
    }


    /**
     * 签到列表
     */
    public function signInList($user_id){
        $responseResult = $this->goldBeanMapper->signInList($user_id);
        return $this->success($responseResult);
    }


    /**
     * 用户签到
     */
    public function signIn($user_id){
        $responseResult = $this->goldBeanMapper->signIn($user_id);
        if(!$responseResult['status']){
            return $this->error($responseResult['msg']);
        }
        return $this->success($responseResult['data']);
    }


    /**
     * 金豆去完成任务
     */
    public function taskType($user_id,$taskId){
        $responseResult = $this->goldBeanMapper->taskType($user_id,$taskId);
        if(!$responseResult['status']){
            return $this->error($responseResult['msg']);
        }
        return $this->success($responseResult['data']);
    }


    /**
     * 金豆去完成任务
     */
    public function goldBeanLog($user_id,$page,$pageSize){
        $responseResult = $this->goldBeanMapper->goldBeanLog($user_id,$page,$pageSize);
        return $this->success($responseResult);
    }


    /**
     * 金豆商城列表
     */
    public function selfGoodsList($page,$pageSize){
        $page = ($page >= 1) ? ($page-1) * $pageSize : $page;
        $TSelfGoods = new TSelfGoods();
        $where = [
            ["deleted","=",0],
            ["status","=",1],
            ["goods_type","=",1],
            ["check_status","=",1],
            ["stock",">",0]
        ];
        $responseResult = $TSelfGoods::query()
            ->select(["self_goods_id","goods_name","goods_img","price","gold_bean","sales"])
            ->where($where)
            ->orderBy("recommend","DESC")
            ->offset($page)
            ->limit($pageSize)
            ->get()
            ->toArray();
        return $this->success($responseResult);
    }
}